package cn.yh.springbootjwt.controller;

import cn.yh.springbootjwt.common.AjaxResult;
import cn.yh.springbootjwt.controller.base.BaseController;
import cn.yh.springbootjwt.domain.query.ShoppingCartUpdate;
import cn.yh.springbootjwt.domain.vo.ShoppingCartListVo;
import cn.yh.springbootjwt.service.IShoppingCartService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/shoppingCart")
@Api(tags = "购物车管理接口")
public class ShoppingCartController extends BaseController {
    @Autowired
    private IShoppingCartService shoppingService;

    @ApiOperation("添加购物车")
    @PostMapping("/{productId}")
    @ApiImplicitParam(name = "productId", value = "商品id", required = true, dataType = "Integer")
    public AjaxResult addShoppingCart(@PathVariable  Long productId){
        return toAjax(shoppingService.addShoppingCart(productId));
    }

    @ApiOperation("购物车列表")
    @GetMapping("/list")
    public AjaxResult<ShoppingCartListVo> selectShoppingCartList(){
        return AjaxResult.success(shoppingService.selectShoppingCartList());
    }

    @ApiOperation("更新购物车")
    @PutMapping("/update")
    public AjaxResult updateShoppingCart(@RequestBody ShoppingCartUpdate shoppingCartUpdate){
        return toAjax(shoppingService.updateShoppingCart(shoppingCartUpdate));
    }

    @ApiOperation("删除购物车")
    @DeleteMapping("/delete/{shoppingCartId}")
    @ApiImplicitParam(name = "shoppingCartId", value = "购物车id", required = true, dataType = "Integer")
    public AjaxResult deleteShoppingCart(@PathVariable Long shoppingCartId){
        return toAjax(shoppingService.deleteShoppingCart(shoppingCartId));
    }

}
